package com.auction.controller.admin;

import com.auction.dto.AuctionCategoryPageQuery;
import com.auction.pojo.AuctionCategory;
import com.auction.pojo.PageResult;
import com.auction.pojo.Result;
import com.auction.service.CategoryService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("adminCategoryController")
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 添加类目
     * 
     * @param category
     * @return
     */
    @PostMapping
    public Result<String> add(@RequestBody AuctionCategory category) {
        log.info("添加类目：{}", category);
        categoryService.add(category);
        return Result.success("添加成功");
    }

    /**
     * 更新类目
     * 
     * @param category
     * @return
     */
    @PutMapping
    public Result<String> update(@RequestBody AuctionCategory category) {
        log.info("更新类目：{}", category);
        categoryService.update(category);
        return Result.success("更新成功");
    }

    /**
     * 删除类目
     * 
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable Long id) {
        log.info("删除类目：{}", id);
        categoryService.delete(id);
        return Result.success("删除成功");
    }

    /**
     * 分页查询类目列表
     *
     * @param categoryPageQuery
     * @return
     */
    @GetMapping("/page")
    public Result <PageResult> page(AuctionCategoryPageQuery categoryPageQuery) {
        log.info("分页查询类目列表：{}", categoryPageQuery);
        PageResult pageResult = categoryService.pageQuery(categoryPageQuery);
        return Result.success(pageResult);
    }

    /**
     * 启用禁用类目
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status,Long id) {
        log.info("启用禁用类目：{},{}", status, id);
        categoryService.startOrStop(status, id);
        return Result.success();
    }
}